class TextAppResponse {
  final int code;
  final String msg;
  final AppItem data;

  TextAppResponse({
    required this.code,
    required this.msg,
    required this.data,
  });

  factory TextAppResponse.fromJson(Map<String, dynamic> json) {
    return TextAppResponse(
      code: json['code'],
      msg: json['msg'],
      data: AppItem.fromJson(json['data']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'msg': msg,
      'data': data.toJson(),
    };
  }
}

class AppItem {
  String name;
  String icon;
  int id;
  List<FormItem> formList;

  AppItem({
    required this.name,
    required this.icon,
    required this.id,
    required this.formList,
  });

  factory AppItem.fromJson(Map<String, dynamic> json) {
    return AppItem(
      name: json['name'],
      icon: json['icon']??"",
      id: json['id'],
      formList: (json['formList'] as List<dynamic>).map((item)=>FormItem.fromJson(item as Map<String, dynamic>)).toList(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'icon': icon,
      'id': id,
      'formList': formList,
    };
  }

  static init() {
    return AppItem(name: "", icon: "", id: 0, formList: [FormItem.init()]);
  }
}

class FormItem {
  String label;
  String value;
  List<String> options;
  String formType;
  bool isRequired;
  String placeholder;
  int min;
  int max;
  int maxLines;
  int minLines;

  FormItem({
    required this.label,
    required this.value,
    required this.options,
    required this.formType,
    required this.isRequired,
    required this.placeholder,
    required this.min,
    required this.max,
    required this.maxLines,
    required this.minLines,
  });

  factory FormItem.fromJson(Map<String, dynamic> json) {
    return FormItem(
      label: json['label']??"",
      value: json['value']??"",
      formType: json['formType']??"text",
      isRequired: json['isRequired']??false,
      placeholder: json['placeholder']??"",
      min: json['min']??0,
      max: json['max']??100,
      maxLines: json['maxLines']??1,
      minLines: json['minLines']??1,
      options: (json['options'] as List<dynamic>).map((item)=>item as String).toList(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'label': label,
      'value': value,
      'formType': formType,
      'isRequired': isRequired,
      'placeholder': placeholder,
      'min': min,
      'max': max,
      'maxLines': maxLines,
      'minLines': minLines,
      'options': options,
    };
  }

  static FormItem init() {
    return FormItem(
        label: "",
        value: "",
        options: [],
        formType: "",
        isRequired: false,
        placeholder: "",
        min: 0,
        max: 0,
        maxLines: 0,
        minLines: 0);
  }
}
